<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.dfhj.duss.util.CalUtil" %>
<%--获取流水号--%>
<%
    JSONObject jsonData = new JSONObject();
    RecordSet rs = new RecordSet();
    String requestid = Util.null2String( request.getParameter( "requestid" ) );
    out.print(">>>>>requestid="+requestid+"<br/>");
    String tablename = "formtable_main_193";
    rs.executeQuery( "select cghtbh,htbhdxwb,lsh,splsh from " + tablename + " where requestid=?", requestid );
    rs.next();
    String cghtbh = Util.null2String( rs.getString( "cghtbh" ) );//采购合同编号
    String htbhdxwb = Util.null2String( rs.getString( "htbhdxwb" ) );//采购合同编号
    String lsh = Util.null2String( rs.getString( "lsh" ) );//流水号
    String splsh = Util.null2String( rs.getString( "splsh" ) );//流水号
    out.print(">>>>>cghtbh="+cghtbh+"<br/>");
    out.print(">>>>>lsh="+lsh+"<br/>");
    if(!"".equals( splsh )){
        if("".equals( lsh )){//防止有退回流程的情况，重复生成流水号
            String maxlsh  = getMaxLsh(tablename,cghtbh);
            out.print(">>>>>maxlsh="+maxlsh+"<br/>");
            maxlsh = "".equals(maxlsh)?"1":maxlsh;
            String newlsh = CalUtil.fAdd(maxlsh,"1");
            String newhtbh = htbhdxwb.substring(0,htbhdxwb.length()-1)+newlsh;
            String sql = "update "+tablename+" set lsh=?,htbh=? where requestid=?";
            rs.executeUpdate(sql,newlsh,newhtbh,requestid);
            out.print(">>>>>sql="+sql+",newlsh="+newlsh+",newhtbh="+newhtbh+"<br/>");
        }
    }
    jsonData.put( "cghtbh", cghtbh );
    out.print( jsonData.toJSONString() );
%>
<%!
    public static String getMaxLsh(String tablename,String htbh){
        RecordSet rs = new RecordSet(  );
        rs.executeQuery("select max(lsh) from "+tablename+" where htbh=?",htbh);
        rs.next();
        return Util.null2String(rs.getString(1));
    }
%>